// pages/user/register/verify/verify.js
var aliyun_api = require('../../../../utils/aliyun-api-gateway.js');
var util = require('../../../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    vercode: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  formsubmit1:function(e){
    console.log(e.detail.value.phone)
    console.log("获取验证码")
    var that = this
    const params = {
      url: 'https://api.link.aliyun.com/kvstore/get',
      apiVer: '1.1.0',
      param: {
        "key": e.detail.value.phone
      }
    }
    aliyun_api.request(params).then(function (res) {

      //  console.log(data)
      if (res.data) {
        wx.showToast({
          title: '账号已存在',
          icon: 'none',
          duration: 2000
        })
      } else {
        var vercode = util.SendSms(e.detail.value.phone)
        that.setData({
          vercode: vercode
        })
      }
    })
  },
  formsubmit:function(e){
    console.log(e.detail.value)
    console.log("下一步")

    var that = this
    if (e.detail.value.phone === '') {
      wx.showToast({
        title: '请填写手机号',
        icon: 'none',
        duration: 2000
      })
    }
    else if (e.detail.value.vercode === that.data.vercode) {
      wx.navigateTo({
        url: '../password/password?phone=' + e.detail.value.phone,
      })
    }
    else{
      wx.showToast({
        title: '验证码错误',
        icon: 'none',
        duration: 2000
      })
    }
  },
})

// var value = {
//   id: '123456789',
//   password: '123',
//   list : [{
//     pk: '1',
//     dn: '1'},
//     {
//     pk: '1',
//     dn: '2'
//     }]
// }